package org.example.examfx02.entity;

import org.example.examfx02.tool.SystemData;

import java.util.List;

public class CourseSelectManager {
    private List<SelectCourse> scList;
    private final static CourseSelectManager instance = new CourseSelectManager();
    private CourseSelectManager(){}
    public static CourseSelectManager getInstance(){
        return instance;
    }

    public List<SelectCourse> getScList() {
        return scList;
    }
    public void setScList(List<SelectCourse> scList) {
        this.scList = scList;
    }
    // 选课
    public boolean add(SelectCourse sc){
        SystemData sys = SystemData.getInstance();
        CourseChoose course = (CourseChoose) sys.getCourseById(sc.getCourseId());
        if(course.getChooseNum()+1>course.getMaxNum()){
            return false;
        }else{
            scList.add(sc);
            course.setChooseNum(course.getChooseNum()+1);
        }
        return true;
    }
    // 退课
    public void remove(SelectCourse sc){
        SystemData sys = SystemData.getInstance();
        CourseChoose course = (CourseChoose) sys.getCourseById(sc.getCourseId());

        scList.remove(sc);
        course.setChooseNum(course.getChooseNum()-1);
    }
}
